import { useModel } from "umi";
import { useEffect } from "react";

import useGatewayPersonInfo from "../../hooks/person/useGatewayPersonInfo";

import PersonDatabase from "./Database";

const PersonFullInfo = () => {
    const { baseInfo } = useModel("person.info");
    const { selectedGateway, setCurrentPerson, selectedPerson } = useModel("gateway.info");
    const { loadGatewayPersonInfo } = useGatewayPersonInfo();

    const loadPersonInfo = () => {
        loadGatewayPersonInfo((res) => {
            setCurrentPerson(res);
        });
    };

    useEffect(() => {
        selectedGateway?.url && loadPersonInfo();
    }, [selectedGateway]);

    if (!baseInfo.uuid) return <></>;

    return <div>{selectedPerson?.uuid && <PersonDatabase reloadData={loadPersonInfo} />}</div>;
};

export default PersonFullInfo;
